package com.come4loves.game.module.fight.helper;

import com.come4loves.core.comunicate.protocol.Response;
import com.come4loves.core.context.SpringContext;
import com.come4loves.game.module.fight.model.ShowCardData;
import com.come4loves.game.proto.BattleCmd;
import com.come4loves.game.proto.BattleProto;
import com.come4loves.game.proto.ModuleName;
import com.come4loves.game.server.session.PlayerContext;

public class FightPushHelper {
	/**
	 * 推送动作
	 * @param actorId
	 * @param recorder
	 */
	public static void pushFightActionRecorder(long actorId, ActionRecorder recorder) {
		if (recorder.actionSize() <= 0) {
			return;
		}
		PlayerContext cotenxt = (PlayerContext) SpringContext.getBean(PlayerContext.class);
		BattleProto.BattleActionResponse.Builder builder = BattleProto.BattleActionResponse.newBuilder();
		builder.addAllActs(recorder.toGeneralAct());
		Response response = Response.valueOf((byte)ModuleName.Module.BATTLE_VALUE, (byte)BattleCmd.Battle.PUSH_BATTLE_ACTION_VALUE, 0, builder.build().toByteArray());
		cotenxt.push(actorId, response );
	}
	/**
	 * 推送使用卡牌
	 * @param actorId
	 * @param showCardData
	 * @param recorder
	 */
	public static void pushUseCard(long actorId, ShowCardData showCardData, ActionRecorder recorder) {
		PlayerContext cotenxt = (PlayerContext) SpringContext.getBean(PlayerContext.class);
		BattleProto.UseCardsResponse.Builder showCardsResponseBuilder = BattleProto.UseCardsResponse.newBuilder();
		BattleProto.UseCardData.Builder builder = BattleProto.UseCardData.newBuilder();
		builder.setId(showCardData.getCardId());
		builder.addAllTargetId(showCardData.getTargetCardIds());
		showCardsResponseBuilder.setData(builder);
		showCardsResponseBuilder.addAllActs(recorder.toGeneralAct());
		Response response = Response.valueOf((byte)ModuleName.Module.BATTLE_VALUE, (byte)BattleCmd.Battle.PUSH_BATTLE_USE_CARD_VALUE, 0, showCardsResponseBuilder.build().toByteArray());
		cotenxt.push(actorId, response );
		
		
	}
}
